1 module firecracker_d.models.snapshot;
2 import firecracker_d.models.base_model;
3 
4 struct SnapshotCreateParams {
5     mixin BaseModel;
6 
7     /***
8     * Path to the file that will contain the guest memory.
9     ***/
10     @serializationRequired
11     @serializationKeys("mem_file_path") string memFilePath;
12 
13     /***
14     * Path to the file that will contain the microVM state.
15     ***/
16     @serializationRequired
17     @serializationKeys("snapshot_path") string snapshotPath;
18 
19     enum SnapshotTypes : string {
20         full = "Full",
21         diff = "Diff"
22     }
23 
24     /***
25     * Type of snapshot to create. It is optional and by default, a full snapshot is created.
26     ***/
27     @serializationKeys("snapshot_type") SnapshotTypes type;
28 
29     /***
30     * The microVM version for which we want to create the snapshot. It is optional and it defaults to the current version.
31     ***/
32     @serializationKeys("version") string version_;
33 
34     /***
35     * Creates a new snapshot.
36     * The microVM should be in the Paused state. 
37     * Throws: FirecrackerException on error.
38     ***/
39     bool put(FirecrackerAPIClient cl) {
40         Response r = cl.put("/snapshot/create", this.stringify);
41         if (r.code == 204) {
42             return true;
43         } else {
44             throwFromResponse(r);
45             return false;
46         }
47     }
48 }
49 
50 /***
51 * Snapshot loading parameters
52 ***/
53 struct SnapshotLoadParams {
54     mixin BaseModel;
55 
56     /***
57     * Enable support for incremental (diff) snapshots by tracking dirty guest pages.
58     ***/
59     @serializationKeys("enable_diff_snapshots") bool enableDiffSnapshots;
60 
61     /***
62     * Path to the file that contains the guest memory to be loaded.
63     ***/
64     @serializationRequired
65     @serializationKeys("mem_file_path") string memFilePath;
66 
67     /***
68     * Path to the file that contains the microVM state to be loaded.
69     ***/
70     @serializationRequired
71     @serializationKeys("snapshot_path") string snapshotPath;
72 
73     /***
74     * Loads a snapshot. Pre-boot only.
75     * Only accepted on a fresh Firecracker process (before configuring any resource other than the Logger and Metrics). 
76     * Throws: FirecrackerException on error.
77     ***/
78     bool put(FirecrackerAPIClient cl) {
79         Response r = cl.put("/snapshot/load", this.stringify);
80         if (r.code == 204) {
81             return true;
82         } else {
83             throwFromResponse(r);
84             return false;
85         }
86     }
87 }
88